layui.define([ 'form', 'laydate', 'table' ], function(exports) {
    var form = layui.form;
    var laydate = layui.laydate;
    var table = layui.table;
    var coreNoticeTable = null;
    var view ={
        init:function(){
            this.initTable();
            this.initSearchForm();
            this.initToolBar();
            window.dataReload = function(){
                Lib.doSearchForm($("#searchForm"),coreNoticeTable);
                Lib.cleanSearchForm($("#searchForm"),coreNoticeTable);
            }
        },
        initTable:function(){
            coreNoticeTable = table.render({
                elem : '#coreNoticeTable',
                height : Lib.getTableHeight(1),
                cellMinWidth: 100,
                method : 'post',
                url : Common.ctxPath + '/cms/coreNotice/list.json' // 数据接口
                ,page: true// 开启分页
                ,limit : 10,
                cols : [ [ // 表头
                    {
                        type : 'checkbox',
                        fixed:'left',
                    },
                {

                    field : 'id', 
                        title : 'id',
                    fixed:'left',
                        width : 60,
                },
                {

                    field : 'type',
                        title : '类型',
                },
                {

                    field : 'title', 
                        title : '标题',
                },
                {

                    field : 'createTime', 
                        title : '创建时间',
                },

            {
                    fixed : 'right',
                    title : '操作',
                    align : 'center',
                    toolbar : '#toobar',
                    width:200
                 }
        ] ]

        });
            table.on('checkbox(coreNoticeTable)', function(obj){
                var coreNotice = obj.data;
                if(obj.checked){
                    //按钮逻辑Lib.buttonEnable()
                }else{

                }
            })
            //监听工具条
            table.on('tool(coreNoticeTable)', function(obj) {
                var data = obj.data; //获得当前行数据
                var layEvent = obj.event; //获得 lay-event 对应的值
                if(layEvent === 'update'){
                    var url = "/cms/coreNotice/edit.do?id="+data.id;
                    Common.openDlg(url,"公告智讯管理>"+data.id+">编辑");
                }else if(layEvent === 'del'){
                    layui.use(['del'], function(){
                        var delView = layui.del;
                        delView.delRow(data);
                    });
                }
            });

        },
        initSearchForm:function(){
            Lib.initSearchForm( $("#searchForm"),coreNoticeTable,form);
        },
        initToolBar:function(){
            toolbar = {
                add : function() { // 获取选中数据
                    var url = "/cms/coreNotice/add.do";
                    Common.openDlg(url,"公告智讯管理>新增");
                },
                batchDel : function() {
                    layui.use(['del'], function(){
                        var delView = layui.del
                        delView.delBatch();
                    });
                }
               };

            //监听工具条
            layui.table.on('tool(coreNoticeTable)', function(obj) {
                var data = obj.data //获得当前行数据
                    , layEvent = obj.event; //获得 lay-event 对应的值
                if(layEvent === 'update'){
                    var url = "/cms/coreNotice/edit.do?id="+data.id;
                    Common.openDlg(url,"编辑");
                }else if(layEvent=='del') {
                    layui.use(['del'], function(){
                        var delView = layui.del;
                        delView.delRow(data);
                    });
                }
            });
            $('.ext-toolbar').on('click', function() {
        var type = $(this).data('type');
        toolbar[type] ? toolbar[type].call(this) : '';
    });
        }
     };
    exports('index',view);

});